<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>面试填报</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <div style="height: 10px;"></div>
        <tips optionTemplate="InterviewFilling"></tips>
        <el-form label-width="80px" ref="editForm">
          <!--          <el-button @click="submitFromFn" size="small" type="primary" plain>保存考核项</el-button>-->
          <div class="resruitment-title"><p>面试考核结论</p></div>
          <div>
            <el-input
                type="textarea"
                :rows="4"
                placeholder="请输入面试记录内容，如语言能力，知识能力，表达能力等"
                v-model="opinion">
            </el-input>
          </div>
          <div class="resruitment-title"><p>试用期考核项</p></div>
          <div class="boxInterview">
            <el-button size="mini" type="primary" plain @click="showAssessmentFn(0)" class="mb-10">新增考核项
            </el-button>
            <el-table
                :data="assessment"
                stripe
                border
                style="width: 100%">
              <el-table-column
                  prop="content"
                  label="考核内容"
                  align="center">
              </el-table-column>
              <el-table-column
                  prop="end_time"
                  label="考核限期"
                  align="center">
              </el-table-column>
              <el-table-column
                  prop="address"
                  label="操作"
                  width="180"
                  align="center">
                <template slot-scope="scope">
                  <el-button size="mini" @click="showAssessmentFn(scope.row.id)">编辑</el-button>
                  <el-button size="mini" type="danger" plain @click="handleDetel(scope.$index)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>

          <div class="resruitment-title"><p>审核人会签</p>
            <el-button @click="signFn" size="mini" type="primary" plain>刷新</el-button>
          </div>
          <div class="boxInterview">
            <div class="signBox">
              <div class="signList" v-for="item in signList" :key="item.id">
                <img :src="item.pic" alt="" v-if="item.pic">
                <!--                <p>{{`${item.realname}（已会签）`}}</p>-->
                <p>
                  <el-tag :type="item.is_autograph?'success':'danger'" @click="getAutogragh(item)" class="tagBox">{{item.realname}}{{ item.is_autograph ? '（已会签）' : '（未会签）' }}
                  </el-tag>
                </p>
              </div>
            </div>
<!--            <el-tag v-for="item in signList" :type="item.is_autograph?'success':'danger'" :key="item.id"-->
<!--                    class="mr-10 tagBox" @click="getAutogragh(item)">{{-->
<!--                item.realname-->
<!--              }}{{ item.is_autograph ? '（已会签）' : '（未会签）' }}-->
<!--            </el-tag>-->
          </div>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button @click="submitFromFn" size="small" type="primary">提交会签</el-button>
                <el-button @click="getInterviewPassed(2)" size="small" type="danger" plain>不符合
                </el-button>
      </div>
    </div>
    <!--    考核项目-->
    <assessmentPopup :assessmentId="assessmentId" :visible.sync="assessmentVisible" @InitFn="InitFn"
                     :resumeId="resumeId"></assessmentPopup>
    <!--    会签审核人 signType 1 面试签字 2 考核签字-->
    <autograghUser :visible.sync="autograghVisible" @signFn="signFn" :userOption="userOption"
                   :resumeId="resumeId" signType="1"></autograghUser>
  </div>
</template>

<script>
import assessmentPopup from "./assessmentPopup";
import autograghUser from "./autograghUser";

export default {
  props: ['visible','resumeId'], // recruitmentType examine 审核 , 'resumeId'
  components: {
    assessmentPopup,
    autograghUser
  },
  data() {
    return {
      dialogVisible: false,
      assessmentVisible: false,
      assessmentId: 0, // 考核项
      assessment: [], // 考核项目
      autograghVisible: false,
      userOption: null, // 签名人信息
      signList: [],// sign审核签字
      opinion: ''
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.InitFn()
        this.signFn() //  会签信息
      }
    }
  },
  created() {
  },
  methods: {
    async submitFromFn() {
      // 此处需要判断考核项是否有
      // 签名是否都有
      if(!this.assessment.length){
        this.$message.error('考核项至少一项')
        return
      }
      let status = 1
      for(let i in this.signList){
        if(!this.signList[i].pic){
          status = 0
        }
      }
      if(!status){
        this.$message.error('审核人未签名确认')
        return
      }
      let data = await this.$post(this.api.recruit.interview.adopt, {id: this.resumeId,opinion: this.opinion});
      if(!data.code){
        this.$message.success(data.msg)
        this.$emit('getResumeDetail', 'initDetail')
        this.closePOpup()
      }else{
        this.$message.error(data.msg)
      }
    },
    // 获取项目列表
    async InitFn() {
      let data = await this.$fetch(this.api.recruit.examine.index, {resume_id: this.resumeId});
      if (!data.code) {
        console.log('data物料信息:', data)
        this.assessment = data.list.data
      } else {
        this.$message.error(data.msg)
      }
    },
    async signFn() {
      let data = await this.$fetch(this.api.recruit.interview.autograph, {id: this.resumeId});
      if (!data.code) {
        console.log('请求会签:', data)
        this.signList = this.getJson(data.list)
      }
    },

    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    showAssessmentFn(option) {
      this.assessmentId = option;
      this.assessmentVisible = true;
    },
    handleDetel(index) {
      let n = this;
      this.$confirm('确认删除该项目考核, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        n.detelRespon(index)
      }).catch(() => {
      })
    },
    // 获取详情
    async detelRespon(index) {
      let data = await this.$fetch(this.api.recruit.examine.delete, {id: this.assessment[index].id});
      if (!data.code) {
        this.$message.success(data.msg)
        this.assessment.splice(index, 1)
      } else {
        this.$message.error(data.msg)
      }
    },
    getAutogragh(option) {
      if(!option.is_autograph){
        this.userOption = this.getJson(option);
        this.autograghVisible = true;
      }
    },
    getInterviewPassed() {
      // 此处驳回需要填写审核结论
      if(!this.opinion){
        this.$message.error('请填写考核结论')
        return
      }
      let status = 1
      for(let i in this.signList){
        if(!this.signList[i].pic){
          status = 0
        }
      }
      if(!status){
        this.$message.error('审核人未签名确认')
        return
      }
      this.$confirm('面试不符确认驳回, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.rejectUserFn()
      }).catch(() => {
      });
    },
    // 驳回简历
    async rejectUserFn() {
      let data = await this.$post(this.api.recruit.interview.reject, {id: this.resumeId, content: this.opinion});
      console.log('data:', data)
      if (!data.code) {
        this.$message.success(data.msg)
        this.$emit('getResumeDetail', 'initDetail')
        this.closePOpup()
      } else {
        this.$message.error(data.msg)
      }
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 70%;
  height: 70%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
  z-index: 9;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 0 20px 10px 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 10px 0 5px;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
}

.resruitment-title p {
  flex: 1;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}

.tagBox {
  cursor: pointer;
}

.boxInterview {
  padding: 0 20px;
}
.signBox{
  display: flex;
}
.signList{
  flex:1;
  text-align: center;
}
.signList img{
  width: 80%;
}
</style>


